home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c / 43 < prev    next >
Text File  |  1996-08-06  |  4KB  |  106 lines

  1. Path: mail2news.demon.co.uk!genesis.demon.co.uk
  2. From: Lawrence Kirby <fred@genesis.demon.co.uk>
  3. Newsgroups: comp.std.c
  4. Subject: Re: Undefined result vs. int's holding undefined values.
  5. Date: Sat, 06 Jan 96 17:59:00 GMT
  6. Organization: none
  7. Message-ID: <820951140snz@genesis.demon.co.uk>
  8. References: <4ck70b$rd7@news.informix.com> <4ckms5$rd7@news.informix.com>
  9. Reply-To: fred@genesis.demon.co.uk
  10. X-NNTP-Posting-Host: genesis.demon.co.uk
  11. X-Newsreader: Demon Internet Simple News v1.27
  12. X-Mail2News-Path: genesis.demon.co.uk
  13.  
  14. In article <4ckms5$rd7@news.informix.com>
  15.            dwood@informix.com "Daniel Wood" writes:
  16.  
  17. >Someone has pointed out(Besides my return address being wrong) that the
  18. >correct term in the following is "undefined behavior" not "undefined result"
  19. >and that the behavior stems from trying to store the value in the object.
  20.  
  21. No, the undefined behaviour stems from the calculation of the value. If f
  22. were simply defined as:
  23.  
  24. void f(int x, int y)
  25. {
  26.     x-y;
  27. }
  28.  
  29. it would still result in undefined behaviour.
  30.  
  31. >One of the undefined behaviors could be to core dump.
  32.  
  33. True, and that might happen as a result of an arithmetic overflow exception,
  34. but doesn't have to.
  35.  
  36. >That still avoids the question of once we have stored something into "r"
  37. >below and the program has NOT core dumped whether it is then acceptable for
  38. >everything >and anything after that to exhibit undefine behavior beyond the
  39. >act of storing the value.
  40.  
  41. Once you have invoked undefined behaviour you can say nothing about the
  42. behaviour of the program from that point on.
  43.  
  44. >ORIGINAL MESSAGE FOLLOWS:
  45. >
  46. >THE TEST CASE, on SCO:
  47.  
  48. 'SCO' is a little woolly here. You could be using (Microsoft based) cc,
  49. (SVR4 based) cc, rcc, icc or gcc. I managed to get the behaviour you describe
  50. with icc. The assembler listing is interesting but not really relevant to 
  51. comp.std.c (in the first case it does a test based on the subtraction, in
  52. the second case the value of the result is tested. Where the subtraction
  53. is valid these will have the same effect).
  54.  
  55. >main() { f(-2147483647, 1879048192); }
  56. >
  57. >f(int x, int y) {
  58. >        int r;
  59. >
  60. >        if ((r=(x-y)) > 0)
  61. >                printf("1: r greater than 0\n");
  62. >
  63. >        if (r > 0)
  64. >                printf("2: r greater than 0\n");
  65. >}
  66. >
  67. >On SCO only the second print occurs.  The reason given to me is that ANSI
  68. >states
  69. >that the result of an overflowing/underflowing operation is undefined.  The
  70. >implementation is free to do what it wants with the result.
  71.  
  72. It is the behaviour that is undefined, not the result (well, if you get a
  73. result that will be undefined too).
  74.  
  75. > This is fine
  76. >with me, however int's, unlike floats, have NO undefined bit patterns
  77.  
  78. Not true (at least not for signed integer types) - i.e. the standard
  79. doesn't prohibit undefined bit patterns.
  80.  
  81. >and
  82. >no matter what you do with the undefined result(Scramble the bits for all
  83. >I care) once you store that something into an int variable that int
  84. >is NOT undefined and allowed to exhibit volatile behavior.
  85.  
  86. It is once undefined behaviour has occurred in the program.
  87.  
  88. >Saying a result is undefined "IS NOT EQUAL TO" saying that a C int variable
  89. >can actually hold an undefined value.
  90.  
  91. A conforming implementation might detect some forms of undefined behaviour
  92. in a program and set a flag which causes random numbers to be applied to all
  93. subsequent operations.
  94.  
  95. > If you think the test case is running
  96. >acceptably, as described above, then tell me the section of the standard that
  97. >states or implies that an int variable can hold an undefined value.
  98.  
  99. Not relevant.
  100.  
  101. -- 
  102. -----------------------------------------
  103. Lawrence Kirby | fred@genesis.demon.co.uk
  104. Wilts, England | 70734.126@compuserve.com
  105. -----------------------------------------
  106.